// gjw/pages/weipai/yuzhan_info.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: 0,
    index: 0,
    content: [
      { photo: 'https://img01.sogoucdn.com/app/a/100520093/e18d20c94006dfe0-feec70b0eb485633-e7e784240dab719c6e65117bcc3abd7a.jpg', name: '林志玲', date: '08-01', txt: '这里是评论内容这里是评论内容这里是评论内容' },
      { photo: 'https://img01.sogoucdn.com/app/a/100520093/e18d20c94006dfe0-feec70b0eb485633-e7e784240dab719c6e65117bcc3abd7a.jpg', name: '林志玲', date: '08-01', txt: '这里是评论内容这里是评论内容这里是评论内容' },
    ],
    box: true,
  },

  tabClick: function (e) {
    this.setData({
      sliderOffset: e.currentTarget.dataset.offsetLeft,
      activeIndex: e.currentTarget.dataset.index
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    options.img = options.img.split(',')
    options.time = options.time.slice(5, 11)
		var siteUrl = wx.getStorageSync('siteUrl')
    that.setData({
      info: options,
      siteUrl: siteUrl
    })
    that.countdown()
  },

  // 查看大图
  previewImage: function (e) {
    var that = this
    var url = that.data.siteUrl   // {{siteUrl}}attachment/wff/    地址前缀
    var urls = []
    var current
    var index = e.currentTarget.dataset.index   //当前点击的下标
    var pictures = that.data.info.img

    for (let i in pictures) {
      urls.push(url + 'attachment/' + pictures[i])
    }
    wx.previewImage({
      current: url + 'attachment/' + pictures[index],
      urls: urls
    })
  },


  // 时间
  countdown: function (time) {
    var that = this
    var EndTime = that.data.info.fromtimesjc
    var NowTime = Math.round(new Date().getTime() / 1000)
    var total_micro_second = EndTime - NowTime
    if (total_micro_second <= 0) {   //倒计时结束
      // app.util.request({
      //   url: 'entry/wxapp/UpdateGroup',
      //   data: {
      //     store_id: that.data.id
      //   },
      //   success: res => {
      //   }
      // })
      // that.setData({
      //   clock: false
      // });

      
    } else if (total_micro_second > 0) {
      that.dateformat(total_micro_second)
      setTimeout(function () {
        total_micro_second -= 1000;
        that.countdown(time);
      }, 1000)
    }

  },

  dateformat: function (e) {
    var that = this
    // 总秒数
    var second = Math.floor(e);
    // 天数
    var day = Math.floor(second / 3600 / 24);
    // 小时
    var hr = Math.floor(second / 3600 % 24);
    // 分钟
    var min = Math.floor(second / 60 % 60);
    // 秒
    var sec = Math.floor(second % 60);
    if (day < 10) {
      day = '0' + day
    }
    if (hr < 10) {
      hr = '0' + hr
    }
    if (sec < 10) {
      sec = '0' + sec
    }
    if (min < 10) {
      min = '0' + min
    }
    that.setData({
      day: day,
      hour: hr,
      min: min,
      sec: sec
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
		this.videoContext = wx.createVideoContext('myVideo')
	}, 
	play: function (e) {
		this.videoContext.requestFullScreen()
	},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})